<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Midterm_Lab6</title>
<link rel="stylesheet" type="text/css"
	href="view/public/css/bootstrap.css" />
<link rel="stylesheet" type="text/css"
	href="view/public/css/bootstrap-responsive.css" />
</head>
<body>
	<div align="left">
		<form action="exam1.php" method="post" class="form-horizontal">
			<h4>ข้อที่ 1</h4>
			กรุณากรอกรหัสลูกค้า
			<input class="input-medium" name="total" type="text"
				placeholder="กรุณากรอกรหัสลูกค้า"> 
				
			<button class="btn btn-small" type="submit">OK</button>
		</form>
		<?php if(isset($_POST['id']) ){
			$p = $_POST['id'];
	
			cal1($p);
}?>
</div>
<?php 
Class Customers{
	private $cusName,$cusId,$rating,$address1,$address2;
	
	public function __construct($cusId,$cusName,$rating,$address1,$address2){
		$this->cusId=$cusId;
		$this->cusName=$cusName;
		$this->rating=$rating;
		$this->address1=$address1;	
		$this->address2=$address2;
	}
	
	public function getcusName(){//เมธอด get
		return $this->cusName;
	}
	public function setIcusName($CN){// เมธอดset
		$this->cusName = $CN;
	}
	public function getcusId(){//เมธอด get
		return $this->cusName;
	}
	public function setIcusId($CI){// เมธอดset
		$this->cusId = $I;
	}
	public function getrating(){//เมธอด get
		return $this->rating;
	}
	public function setrating($RT){// เมธอดset
		$this->rating = $RT;
	}
	public function getsAddress1(){//เมธอด get
		return $this->address1;
	}
	public function setsAddress1($CA1){// เมธอดset
		$this->address1 = $SA1;
	}
	public function getsAddress2(){//เมธอด get
		return $this->address2;
	}
	public function setsAddress2($CA2){// เมธอดset
		$this->address2 = $CA2;
	}

}

Class Store{
	private $sName,$sAddress;
	
	public function __construct($sName,$sAddress){
		$this->sName=$sName;
		$this->sAddress=$sAddress;
	}
	
	public function getsName(){//เมธอด get
		return $this->sName;
	}
	public function setsName($SN){// เมธอดset
		$this->sName = $SN;
	}
	public function getSaddress(){//เมธอด get
		return $this->sAddress;
	}
	public function setSaddress($SAD){// เมธอดset
		$this->sAddress = $SAD;
		
	}
}

Class ConsumerProducts{
	private $CPId,$CPName,$CPPrice,$CPDiscount,$CPInsurance;
	
	public function __construct($CPId,$CPName,$CPPrice,$CPDiscount,$CPInsurance){
		$this->CPId=$CPId;
		$this->CPName=$CPName;
		$this->CPPrice=$CPPrice;
		$this->CPDiscount=$CPDiscount;
		$this->CPInsurance=$CPInsurance;
		
	}
	public function getCPId(){//เมธอด get
		return $this->CPId;
	}
	public function setCPId($CPI){// เมธอดset
		$this->CPId = $CPI;
	}
	public function getCPName(){//เมธอด get
		return $this->CPName;
	}
	public function setCPName($CPN){// เมธอดset
		$this->CPName = $CPN;
	}
	public function getCPPrice(){//เมธอด get
		return $this->CPPrice;
	}
	public function setCPPrice($CPP){// เมธอดset
		$this->CPPrice = $CPP;
	}
	public function getCPDiscount(){//เมธอด get
		return $this->CPDiscount;
	}
	public function setCPDiscount($CPD){// เมธอดset
		$this->CPDiscount = $CPD;
	}
	public function getCPInsurance(){//เมธอด get
		return $this->CPInsurance;
	}
	public function setCPInsurance($CPIN){// เมธอดset
		$this->CPInsurance = $CPIN;
	}
	
	
}

Class  EntertainmentProducts{
	private $EPId,$EPName,$EPPrice,$EPDiscount,$EPLength;
	
	public function __construct($EPId,$EPName,$EPPrice,$EPDiscount,$EPLength){
		$this->EPId=$EPId;
		$this->EPName=$EPName;
		$this->EPPrice=$EPPrice;
		$this->EPDiscount=$EPDiscount;
		$this->EPLength=$EPLength;
	
	}
	public function getEPId(){//เมธอด get
		return $this->EPId;
	}
	public function setEPId($EPI){// เมธอดset
		$this->EPId = $EPI;
	}
	public function getEPName(){//เมธอด get
		return $this->EPName;
	}
	public function setEPName($EPN){// เมธอดset
		$this->EPName = $EPN;
	}
	public function getEPPrice(){//เมธอด get
		return $this->EPPrice;
	}
	public function setEPPrice($EPP){// เมธอดset
		$this->EPPrice = $EPP;
	}
	public function getEPDiscount(){//เมธอด get
		return $this->EPDiscount;
	}
	public function setEPDiscount($EPD){// เมธอดset
		$this->EPDiscount = $EPD;
	}
	public function getEPLength(){//เมธอด get
		return $this->EPLength;
	}
	public function setEPLength($EPL){// เมธอดset
		$this->EPLength = $EPL;
	}
}

	Class BookProducts{
		private $BPId,$BPName,$BPPrice,$BPDiscount,$BPNumber;
		
		public function __construct($BPId,$BPName,$BPPrice,$BPDiscount,$BPNumber){
			$this->BPId=$BPId;
			$this->BPName=$BPName;
			$this->BPPrice=$BPPrice;
			$this->BPDiscount=$BPDiscount;
			$this->BPLength=$BPLength;
		
		}
		public function getBPId(){//เมธอด get
			return $this->BPId;
		}
		public function setBPId($BPI){// เมธอดset
			$this->BPId = $BPI;
		}
		public function getBPName(){//เมธอด get
			return $this->BPName;
		}
		public function setBPName($BPN){// เมธอดset
			$this->BPName = $BPN;
		}
		public function getBPPrice(){//เมธอด get
			return $this->BPPrice;
		}
		public function setBPPrice($BPP){// เมธอดset
			$this->BPPrice = $BPP;
		}
		public function getBPDiscount(){//เมธอด get
			return $this->EPDiscount;
		}
		public function setBPDiscount($BPD){// เมธอดset
			$this->BPDiscount = $BPD;
		}
		public function getBPNumber(){//เมธอด get
			return $this->BPNumber;
		}
		public function setBPNumber($BPN){// เมธอดset
			$this->BPNumber = $BPL;
		}
		}
		
		Class Orders{
			private $OrderId,$OrderQty;
			
			public function __construct($OrderId,$OrderQty){
				$this->OrderId=$OrderId;
				$this->OrderQty=$OrderQty;
			}
			public function  getOrderId(){
				return $this->OrderId;
			}
			public function setOrderId($OR){
				$this->OrderQty=$OR;
			}
		
		public function cal1(){
			if($this->OrderId==1001){
				$this->product=2500*$this->OrderQty;
			}
		    else if($this->OrderId==1002){
				$this->product=1600*$this->OrderQty;
			}
			else if($this->OrderId==1003){
				$this->product=780*$this->OrderQty;
			}
			else if($this->OrderId==1004){
				$this->product=5600*$this->OrderQty;
			}
			else if($this->OrderId==1005){
				$this->product=2300*$this->OrderQty;
			}
			else if($this->OrderId==2001){
				$this->product=500*$this->OrderQty;
			}
			else if($this->OrderId==2002){
				$this->product=600*$this->OrderQty;
			}
			else if($this->OrderId==3001){
				$this->product=600*$this->OrderQty;
			}
			else if($this->OrderId==3002){
				$this->product=600*$this->OrderQty;
			}
			else{
				echo "error";
			}
		}
		}
		
		$customers[]= new Customers("CUS0001","นายเทวัญ สกุลเทเวศน์","VIP","23 หมู่บ้านอโศก ตาบลหนองหอย อาเภอสวรรค์ จังหวัดเพชรบูรณ์","19 หมู่ 7 ตาบลหนองหาร อาเภอสันทราย จังหวัดเชียงใหม่");
		$store[]= new Store("ร้านอรุโณทัย","บ้านเลขที่ 23 หมู่ 4 ตาบลหนองหาร อาเภอสันทราย จังหวัดเชียงใหม่");
		$consumerProducts[] = new ConsumerProducts(1001,"เครื่องกรองน้า",2500,0,3);
		$consumerProducts[] = new ConsumerProducts(1002,"ประตูเหล็กดัด",1600,0,1);
		$consumerProducts[] = new ConsumerProducts(1003,"ผ้าม่านประตู",780,2,2);
		$consumerProducts[] = new ConsumerProducts(1004,"เครื่องปรับอากาศ",5600,10,1);
		$consumerProducts[] = new ConsumerProducts(1005,"โต๊ะประชุมสานักงาน",2300,5,1);
	    $entertainmentProducts[] = new EntertainmentProducts(2001,"CD เพลง", 500,0,"20.33 นาที");
	    $entertainmentProducts[] = new EntertainmentProducts(2002,"DVD ภาพยนต์",600,30,"20 : 33 นาที");
	    $bookProducts[] = new BookProducts(3001,"หนังสือ JAVA",600,10,569);
	    $bookProducts[] = new BookProducts(3002,"DVD ภาพยนต์",600,5,300);
	    $orders[]=new Orders(1001,5);
	    $orders[]=new Orders(1003,3);
	    $orders[]=new Orders(1005,6);
	    
	 ?> 
	    		<?php 
	    		$c = $_POST['a1'];
	    		
	    		function code1($code){//แสดงค่าเมื่อผู้ใช้เลือกจำนวนเสร็จ
	    
	    		echo "<table border=\"1\">";
	    		echo "<tr><td>ลำดับ</td>";
	    		echo "<td>หมายเลขบัตรประชาชน</td></tr>";
	    		for($i=1;$i<=$code;$i++){
	    
	    		echo "<tr><td>$i</td>";
	    		echo "<td>";
	    		echo cal();
	    			echo "</td></tr>";
	    }
	    echo "</table>";
	    }
	
	    
	    ?>
	    
	   <?php 
	    		
		$cusId = $_POST['id'];
		
		if(isset($_POST['id'])){
		
			$index=1;
		
		
			$counts =0 ;
			$sum = 0;
			for($i=0;$i<count($orders);$i++){
				if($stuId == $registers[$i]->getStudent()->getStudentId()){
					echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			ใบเสร็จรับเงิน <br>";
					echo "".$store[$i]->getsName()."".$store[$i]->getSaddress();
					echo "<br> ชื่อ ผู้ซื้อ  &nbsp".$customers[$i]->getcusName()."<br>";
					echo "ข้อมูลที่อยู่ 1 :".$customers->getsAddress1()."<br><br>";
					echo "ข้อมูลที่อยู่ 2 :".$customers->getsAddress2()."<br><br>";
					echo "รายการสินค้าสั่งซื้อ<br>";
					echo "-------------------------------------------------------------------------------------------------------------<br>";
					echo "ลำดับ &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp รายการ&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				จำนวน  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp หน่วยละ&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				ส่วนลด  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspจำนวนเงิน <br><br>";
					echo "-------------------------------------------------------------------------------------------------------------<br>";
					break;
				}
			}
			for($j=0;$j<count($registers);$j++){
				if($stuId == $registers[$j]->getStudent()->getStudentId()){
					echo " ".($index++)."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->getSubject()->getSubjectId().
					"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->getSubject()->getSubjectName()."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->checkData()."<br><br>";
		
					$counts += $registers[$j]->getSubject()->getUnit();
					$sum +=  $registers[$j]->getSubject()->getUnit() *$registers[$j]->checkGrade();
				}
			}
			echo "-------------------------------------------------------------------------------------------------------------<br>";
			echo  "หน่วยกิตรวม&nbsp&nbsp&nbsp ".number_format($counts,2)."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
			echo  " GPA &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".number_format (($sum/$counts),2);
		}
	

?>